package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;

import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.util.PinchImageView;

/**
 * User: Administrator
 * Date: 2016/6/24 0024
 * Time: 16:28
 */
public class ShareImgGalleryAdapter extends PagerAdapter {

    private ArrayList<String> mList;
    private Context mContext;

    public ShareImgGalleryAdapter(ArrayList<String> mList, Context mContext) {
        this.mList=mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(mContext, R.layout.gallery_imgitem, null);
        PinchImageView image = (PinchImageView) view.findViewById(R.id.img_banner);
//        Glide.with(mContext).load(OKUtilAPI.imgBaseUrl+mList.get(position)).into(image);
        Glide.with(mContext)
                .load(OKUtilAPI.imgBaseUrl+mList.get(position))
                .thumbnail(0.2f)
                .placeholder(R.mipmap.spinner_48_inner_holo)
                .into(image);

        container.addView(view);
        AutoUtils.auto(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    public class ViewHolder{
        TextView img_tv;
        ImageView iamge;
    }
}
